$(function () {
    chaxun();
});

function chaxun() {
    $.ajax({
        url: '/userFindAll',
        data: '',
        type: 'get',
        dataType: 'json',
        success: function (data) {
            setData(data[0].object);
        }
    })
}

function setData(data) {
    // data = JSON.stringify(data);
    let html = '';
    for (let i = 0; i < data.length; i++) {
        html += '<tr>\n' +
            '        <td>' + data[i].id + '</td>\n' +
            '        <td width="200px">' + data[i].username + '</td>\n' +
            '        <td>' + data[i].password + '</td>\n' +
            '        <td> <a href="javascript:update(' + data[i].id + ')">编辑</a> ' +
            ' <a href="javascript:del(' + data[i].id + ')">删除</a></td>\n' +
            '    </tr>';
    }
    $("#companyTbody").html(html);
}

function update(id) {
    localStorage.setItem("userId", id);
    $('#homeright').load('/back/userUpdate.jsp');
}

function del(id) {
    let userId = localStorage.setItem("userId", id);
    myAjax('/userDel', {id, userId}, 'post');
    $('#homeright').load('/back/usermanage.jsp');
}